<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>最大整除子集</title>
</head>
<body>
  <script>
    function fn(nums) {
      let n = nums.length, f = Array(n).fill(1), ans = 1, tt = 0
      nums.sort((a, b) => a - b)
      for (let i = 0; i < n; i++) {
        for (let j = 0; j < i; j++) {
          if (nums[i] % nums[j] == 0) f[i] = Math.max(f[i], f[j] + 1)
        }
        if (f[i] > ans) {
          ans = f[i], tt = i
        }
      }
      // console.log(ans, tt)
      let arr = []
      for (let i = tt; i >= 0; i--) {
        if (nums[tt] % nums[i] == 0 && f[i] == ans) {
          arr.unshift(nums[i])
          tt = i
          ans--
        }
      }
      return arr
    }
    console.log(fn([1, 2, 3]))
  </script>
</body>
</html>